//
//  MKUpDatePlanCollectionViewCell.m
//  ManKeCartoon
//
//  Created by 邹功梁 on 15/10/23.
//  Copyright © 2015年 ManKe. All rights reserved.
//

#import "MKUpDatePlanCollectionViewCell.h"
#import "MKBaseHeader.h"
@implementation MKUpDatePlanCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        _webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
        _webView.delegate = self;
        [self.contentView addSubview:_webView];
    }
    return self;
}

- (void)setUrl:(NSString *)url
{
    [_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    
//    NSString *currentURL = [webView stringByEvaluatingJavaScriptFromString:@"location.hostname"];
//    NSString *title = [webView stringByEvaluatingJavaScriptFromString:@"document.title"];
//    NSLog(@"title == %@", title);
//    NSLog(@"currentURL == %@", currentURL);
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
//    NSLog(@"%@", request.URL.absoluteString);
    if ([request.URL.absoluteString containsString:@"gocomic"]) {
        MKCartoonViewController *cartoon = [[MKCartoonViewController alloc] init];
        NSString *comic_id = [request.URL.absoluteString substringFromIndex:22];
        cartoon.comic_id = comic_id;
        
        for (UIView* next = [self superview]; next; next = next.superview) {
            // 遍历找到全部响应者
            UIResponder* nextResponder = [next nextResponder];
            // 找到当前Controller响应者
            if ([nextResponder isKindOfClass:[UIViewController class]]) {
                
                UIViewController *controller = (UIViewController*)nextResponder ;
                [controller.navigationController pushViewController:cartoon animated:YES];
            }
        }
    }
    return YES;
}

@end
